from pms.common.views import PostFormula
from department.utils import assert_department_permissions
from department.utils.member import update_department_member, department_member_view
from department.models import Work


class API(PostFormula):

    def handle(self, req):
        assert_department_permissions(self.user.id, req['did'], [3])
        return self.success_respond(
            department_member_view(
                update_department_member(
                    work=Work.objects.get(rid__did_id=req['did'], uid_id=req['uid']),
                    view=req['mod']
                )
            )
        )
